#include <vector>

using namespace std;

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ans_t = nums[0];
        int ans = ans_t;
        for (int i = 1; i < nums.size(); i++) {
            ans_t = max(ans_t + nums[i], nums[i]);
            ans = max(ans_t, ans);
        }
        return ans;
    }
};